//
//  BiCarSaleParser.m
//  TrunkIndustryManageSystem
//
//  Created by 李璐西 on 15-4-6.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

#import "BiCarSaleParser.h"
#import "JSONKit.h"
#import "BiCarSaleCheckEntity.h"

@implementation BiCarSaleParser
SINGLE_INSTANCE_IMPLEMENTION(BiCarSaleParser)

+ (NSArray*)parserCarSaleCheckListEntity:(NSString*)jsonStr
{
    NSMutableArray * array = [NSMutableArray array];
    
    if ([jsonStr isKindOfClass:[NSString class]])
    {

        NSDictionary *jsonDict = [jsonStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
        
        id  data = jsonDict[@"data"];
        
        if ([data isKindOfClass:[NSString class]]) {
            
            BiCarSaleCheckEntity * entity = [[BiCarSaleCheckEntity alloc] init];
            
            entity.responseStatus = jsonDict[@"response_status"];
            
            entity.resultinfo = jsonDict[@"result_info"];
            
            [array addObject:entity];
        }else if ([data isKindOfClass:[NSArray class]]){
        
            NSArray *dataArr = (NSArray *)data;
            
            if (0 == dataArr.count) {
                
                BiCarSaleCheckEntity * entity = [[BiCarSaleCheckEntity alloc] init];
                
                entity.responseStatus = jsonDict[@"response_status"];
                
                entity.resultinfo = jsonDict[@"result_info"];
                
                [array addObject:entity];
            }else{
                
                for (NSInteger i = 0; i < dataArr.count; i++) {
                    
                    NSDictionary * dataDic = dataArr[i];
                    
                    BiCarSaleCheckEntity * entity = [[BiCarSaleCheckEntity alloc] init];
                    
                    entity.responseStatus = jsonDict[@"response_status"];
                    
                    entity.resultinfo = jsonDict[@"result_info"];
                    
                    entity.name = dataDic[@"userApplyName"];
                    
                    entity.destination = dataDic[@"destination"];
                    
                    entity.gooff_time = dataDic[@"gooffTime"];
                    
                    [array addObject:entity];
                }
            }
        }
    }
    
    return array;
}

+ (NSDictionary *)parserCarSaleApplyEntity:(NSString*)jsonStr
{
    
    NSDictionary * jsonDic = [jsonStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:jsonDic];

    return dict;
}


@end
